package jh.adapter

import android.os.Environment
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder

import jh.model.Pic
import com.bumptech.glide.Glide
import android.os.Environment.getExternalStorageDirectory
import android.util.Log
import android.view.Gravity
import android.view.View
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import com.jh.ios.forecast.R
import jh.utils.ScreenUtils
import org.jetbrains.anko.dip
import org.jetbrains.anko.margin
import org.jetbrains.anko.px2dip
import java.io.File


/**
 * Created by apple on 2019/6/9.
 * 上传图片adapter
 */

class PostAdapter(layoutResId: Int, data: ArrayList<Pic>?) : BaseQuickAdapter<Pic, BaseViewHolder>(layoutResId, data) {

    override fun convert(helper: BaseViewHolder, item: Pic) {
        val img_item_pic=helper.getView<ImageView>(R.id.img_item_pic)
        val ll_root_item=helper.getView<LinearLayout>(R.id.ll_root_item)
        val tv_del_pic=helper.getView<TextView>(R.id.tv_del_pic)

        //对根布局设置 设置图片宽高为 屏幕宽度的三分之一 单位px
        val lParam = LinearLayout.LayoutParams(ll_root_item.layoutParams)
        val width=ScreenUtils.getScreenWidth(mContext)
        lParam.width =(width-30) /3
        lParam.height = (width-30) /3
        img_item_pic.scaleType=ImageView.ScaleType.CENTER_CROP
        lParam.margin= 5
        ll_root_item.layoutParams = lParam

        //对ImageView设置
//        val lParam = LinearLayout.LayoutParams(img_item_pic.layoutParams)
//        val width=ScreenUtils.getScreenWidth(mContext)
//        lParam.width =(width-30) /3
//        lParam.height = (width-30) /3
//        img_item_pic.scaleType=ImageView.ScaleType.CENTER_CROP
//        lParam.margin= 5
//        img_item_pic.layoutParams = lParam

        //加载图片
        if (item.picStr=="-1"){
            img_item_pic.setImageResource(R.drawable.ic_add_photo)
            tv_del_pic.visibility= View.GONE
        }else{
            tv_del_pic.visibility= View.VISIBLE
            Glide.with(mContext).load(item.picStr).into(img_item_pic)
        }
    }
}
